package org.dubbo.consumer.service.impl;

import com.typhoon.client.UserReadClient;
import com.typhoon.dto.UserDto;
import org.dubbo.consumer.dto.ResponseBase;
import org.dubbo.consumer.service.ImitateConsumerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service("imitateConsumerService")
public class ImitateConsumerServiceImpl implements ImitateConsumerService /*,ApplicationContextAware */ {

	//private GenericService genericService ;

	@Autowired
	private UserReadClient userReadClient;

	@Override
	public ResponseBase doQueryUserById(Long id) {
		ResponseBase resp = new ResponseBase();
		UserDto userDto = this.userReadClient.queryByPK(id);
//		String methodName = "queryByPK";
//		String[] paramTypes = new String[1];
//		paramTypes[0] = "java.lang.Long";
//		Object[] params = new Object[1];
//		params[0] = id;
//		Object result = this.genericService.$invoke(methodName,paramTypes,params);
		resp.setAttach(userDto);
		return resp;
	}

//	@Override
//	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//		if(null == applicationContext) {
//			throw new IllegalArgumentException("applicationContext未注入");
//		}
////		this.genericService = (GenericService)applicationContext.getBean("userService");
//		// 引用远程服务
//		// 该实例很重量，里面封装了所有与注册中心及服务提供方连接，请缓存
//		ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
//		ApplicationConfig config = new ApplicationConfig();
//		config.setName("dubbo-consumer");
//		reference.setApplication(config);
//		// 弱类型接口名
//		reference.setInterface("com.typhoon.service.UserService");
//		//reference.setVersion("1.0.0");
//		// 声明为泛化接口
//		reference.setGeneric(true);
//		reference.setUrl("dubbo://localhost:20289");
//		reference.setTimeout(30000);
//		reference.setProtocol("dubbo");
//
//		// 用com.alibaba.dubbo.rpc.service.GenericService可以替代所有接口引用
//		this.genericService = reference.get();
//	}
}
